package com.zudada.servermain.task;


import com.zudada.servermain.Service.PortStatsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

@Component
@Slf4j

public class StatsScheduledTask {
    @Autowired
    private PortStatsService portStatsService;

    // 每天凌晨2点执行日统计
    @Scheduled(cron = "0 0 2 * * ?")
    public void dailyStats() {
        log.info("定时执行日统计：{}", LocalDateTime.now());
        portStatsService.calculateAndSaveStats("DAY");
    }

    // 每周一凌晨3点执行周统计
    @Scheduled(cron = "0 0 3 ? * MON")
    public void weeklyStats() {
        log.info("定时执行周统计：{}", LocalDateTime.now());
        portStatsService.calculateAndSaveStats("WEEK");
    }

    // 每月1日凌晨4点执行月统计
    @Scheduled(cron = "0 0 4 1 * ?")
    public void monthlyStats() {
        log.info("定时执行月统计：{}", LocalDateTime.now());
        portStatsService.calculateAndSaveStats("MONTH");
    }

    // 每年1月1日凌晨5点执行年统计
    @Scheduled(cron = "0 0 5 1 1 ?")
    public void yearlyStats() {
        log.info("定时执行年统计：{}", LocalDateTime.now());
        portStatsService.calculateAndSaveStats("YEAR");
    }
}
